package com.onpositive.mediawiki.serializing;

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import com.onpositive.data.serializer.writers.NumericValueCollectionWriter;
import com.onpositive.data.serializer.writers.RangeWriter;
import com.onpositive.datamap.values.impl.ScalarRange;
import com.onpositive.units.ParsedScalar;

public class ScalarValueWriter extends AbstractMediaWikiWriter<ParsedScalar> {

	RangeWriter wr = new RangeWriter();
	
	public ScalarValueWriter() {
		super(ParsedScalar.class);
	}

	@Override
	public void append(ParsedScalar obj) {
		
		if( obj == null ){
			wr.append( null ) ;
			return ;
		}
		
		double lVal, uVal ;
		String comment = obj.getComment() ;
		
		if( obj.isRange() ){
			 lVal = obj.getLowerBound() ;
			 uVal = obj.getUpperBound() ;
		} else{
			lVal = obj.getUpperBound() ;
			uVal = obj.getUpperBound() ;
		}
		
		ScalarRange sr = new ScalarRange( null, comment, lVal, uVal ) ;
		wr.append( sr ) ;
	}

	@Override
	public void serialize(DataOutputStream stream) throws IOException
	{
		wr.serialize( stream ) ;
	}
}

	
